package ui.panel;

import entity.CommonParam;
import others.RectDraw;
import ui.common.CommonPanel;
import ui.label.CoordinateLabel;
import ui.label.LimpidLabel;
import utils.ImageUtils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @version V1.0
 * @Title:
 * @Package
 * @Description:
 * @author: runoob
 * @date:
 */
public class ClickPanel extends CommonPanel {

    private LimpidLabel bgLabel = new LimpidLabel(ImageUtils.common,0, 0, WorkPanel.width-10, WorkPanel.height-30);
    public CoordinateLabel waitLabel = new CoordinateLabel(15, 0, "wait", this);
    public CoordinateLabel walkLabel = new CoordinateLabel(65, 0, "walk", this);
    public CoordinateLabel sleepLabel = new CoordinateLabel(115, 0, "sleep", this);
    public CoordinateLabel danceLabel = new CoordinateLabel(165, 0, "dance", this);
    public CoordinateLabel speak1Label = new CoordinateLabel(215, 0, "speak1", this);
    public CoordinateLabel speak2Label = new CoordinateLabel(265, 0, "speak2", this);
    public Map<Integer, CoordinateLabel> paramMap = new HashMap<>();
    public RectDraw rectDraw = new RectDraw();

    public ClickPanel() throws IOException {
//        load("F:\\out\\桌宠\\碧蓝桌宠\\resources\\安克雷奇\\resources\\image\\wait\\wait1.png");
        this.setBounds(5,81,WorkPanel.width-10,WorkPanel.height-80);
        this.setBorder(null);
        setParamMap();
        addComponent();
    }

    public void load(String path){
        this.remove(rectDraw);
        this.remove(bgLabel);
        rectDraw = new RectDraw(5,5,300,300, path);
        this.add(rectDraw);
        this.add(bgLabel);
        refresh();
    }

    public void setParamMap(){
        paramMap.put(0, waitLabel);
        paramMap.put(1, walkLabel);
        paramMap.put(2, sleepLabel);
        paramMap.put(3, danceLabel);
        paramMap.put(4, speak1Label);
        paramMap.put(5, speak2Label);
    }

    public void addComponent(){
        this.add(waitLabel);
        this.add(walkLabel);
        this.add(sleepLabel);
        this.add(danceLabel);
        this.add(speak1Label);
        this.add(speak2Label);
        this.add(rectDraw);
        this.add(bgLabel);
    }

    public ArrayList<CommonParam> getData(){
        ArrayList<CommonParam> result = new ArrayList<>();
        Set<Map.Entry<Integer, CoordinateLabel>> entries = paramMap.entrySet();
        for (Map.Entry<Integer, CoordinateLabel> entry : entries) {
            CoordinateLabel cache = entry.getValue();
            String head = cache.nameLabel.getText().replace(" ","").replace(":","");
            result.add(new CommonParam(head+".xL",cache.xlField.getText()));
            result.add(new CommonParam(head+".xR",cache.xrField.getText()));
            result.add(new CommonParam(head+".yU",cache.yuField.getText()));
            result.add(new CommonParam(head+".yD",cache.ydField.getText()));
        }
        return result;
    }

    public void refresh(){
        this.invalidate();
        this.validate();
        this.repaint();
    }

}
